home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Interactive Media Design Review 1999
/
Interactive Media Design Review 1999.iso
/
pc
/
Demos
/
Herois
/
Codigo.Cst
/
00012_Script_Anima Sprite
< prev
next >
Wrap
Text File
|
1999-03-19
|
5KB
|
150 lines
property spr
property memberPrim, memberUlt -- Cast members que serao animados
property memPrim, memQuantos -- Membros: em numero
property espera -- Tempo de espera entre cada mudanca (em ticks)
property aleatorio -- True para mudanca aleatoria
property ultimaTroca -- Hora em que foi feita ultima troca
property fotoAtual
property tempoAleatorio
property proxEspera
property delta
property prioridade
property memoria, sorteado, removeSpr
property embaralhaInk
on getBehaviorDescription
return "Anima sprites"
end
on getPropertyDescriptionList
set p_list = [ ¼
#memberPrim: [ #comment: "Primeiro membro da animacao", ¼
#format: #string, ¼
#default: "" ], ¼
#memberUlt: [ #comment: "Ultimo membro da animacao", ¼
#format: #string, ¼
#default: "" ], ¼
#espera: [ #comment: "Espera entre cada troca em 1/60s (velocidade)",¼
#format: #integer,¼
#default: 60 ],¼
#aleatorio: [ #comment: "Animacao randomica",¼
#format: #boolean,¼
#default: false ],¼
#tempoAleatorio: [ #comment: "Tempo de animacao randomica",¼
#format: #boolean,¼
#default: false ],¼
#delta: [ #comment: "Espera no inicio da animacao",¼
#format: #integer,¼
#default: 0 ],¼
#prioridade: [ #comment: "Prioridade da animacao (se anima em momentos criticos)",¼
#format: #integer,¼
#default: 0 ],¼
#memoria: [ #comment: "Memoria minima necessaria para animacao, senao simplesmente sorteia um dos frames",¼
#format: #integer,¼
#default: 0 ],¼
#removeSpr: [ #comment: "Se deve nao mostrar nenhum sprite em caso de memoria curta",¼
#format: #boolean,¼
#default: false ],¼
#EmbaralhaInk: [ #comment: "Varia tambem a maneira de aplicar a imagem",¼
#format: #integer,¼
#default: 0 ]¼
]
return p_list
end
on beginSprite me
set spr = the spriteNum of me
inicializaAnima me
if prioridade < 0 then
set prioridade = 0
end if
end
on inicializaAnima me
global myMemSize
set memPrim to the number of member memberPrim
set memQuantos to (the number of member memberUlt) - memPrim + 1
if myMemSize < memoria * 1024 * 1024 then
set sorteado = true
if removeSpr then
set the member of sprite spr to 1
else
set the member of sprite spr to member (memPrim + random(memQuantos) - 1)
end if
else
set sorteado = false
end if
set proxEspera = random(espera)
put 0 into fotoAtual
set ultimaTroca = 0
if delta > 0 then set the visibility of sprite spr to false
end
on cleanSprite me
puppetSprite (the spriteNum of me),false
set the visibility of sprite spr to true
end
on idleSprite me
if delta = 0 and sorteado then return
if not the visibility of sprite spr and delta = 0 then return
global gMustUpdate
if ultimaTroca = 0 then set ultimaTroca = the timer
set tmp = the timer - ultimaTroca
if delta > 0 and tmp > delta then
set ultimaTroca = the timer
set the visibility of sprite spr to true
set delta = 0
set tmp = 0
set gMustUpdate to true
end if
if sorteado then return
-- Testa se ja e' hora de trocar figura
if tempoAleatorio then
if tmp > proxEspera then
set tmp = true
set proxEspera = random(espera)
else
set tmp = false
end if
else
if tmp > espera then
set tmp = true
else
set tmp = false
end if
end if
-- Troca, se ja' for hora e se nao for em area critica
global gCritico
if tmp and prioridade >= gCritico then
-- Descobre qual a proxima figura a trocar
if (aleatorio) then
set tmp = random(memQuantos - 1) - 1
if tmp >= fotoAtual then set tmp = 1 + tmp
set fotoAtual = tmp
else
set fotoAtual = fotoAtual + 1
if fotoAtual >= memQuantos then set fotoAtual = 0
end if
-- Muda figura e updateStage
set the member of sprite (the spriteNum of me) to memPrim + fotoAtual
if fotoAtual < embaralhaInk then
if random(2) = 1 then
set the ink of sprite (the spriteNum of me) to 3
else
set the ink of sprite (the spriteNum of me) to 36
end if
else if embaralhaInk > 0 then
set the ink of sprite (the spriteNum of me) to 36
end if
set gMustUpdate to true
set ultimaTroca = the timer
end if
end